﻿using System;
using System.Collections.Generic;

namespace QSharp.Scheme.Utility.HBSpaceMgmt
{
    /** 
     * <summary>
     *  The proposed format of the section stream:
     *   number of b-trees
     *   root[0]
     *   root[1]
     *   ...
     *   -- ends where root[btreeCount] would be located
     *   actual number of entries (holes)
     *   Hole[0]
     *   Hole[1]
     *   ...
     *   ...unused space...
     *   -- ends where Hole[rootLen] would be located
     *   
     * </summary>
     *
     * <remarks>
     *  `rootLen' (Maximum number of holes)
     *  and `btreeCount' is needed in encoding and 
     *  decoding the target stream, 
     *  `rootLen' can be deduced from the size (number
     *  of total chunks) of the target stream
     * </remarks>
     */

    public interface IRootEncoder
    {
        void Encode(IList<Hole> holes, IList<IPosition> roots, IStream stream);
        bool Decode(IList<Hole> holes, IList<IPosition> roots, IStream stream);

        ISize EncodedSize { get; }
    }


    /**
     * <summary>
     *  The proposed format of the section stream:
     *   child_count
     *   ENTRY1 (Entry[0]) { holepos, holesize }
     *   ENTRY2 (Entry[1]) { holepos, holesize }
     *   ...
     *   ENTRYn-1 { holepos, holesize }
     *   ---------------------------
     *   PARENT
     *   CHILD1 (Children[0])
     *   CHILD2 (Children[1])
     *   ...
     *   CHILDn
     * 
     * </summary>
     */
    public interface INodeEncoder
    {
        /**
         * <summary>
         *  returns the size of the encoded node
         *  returns null on decoding error
         * </summary>
         */
        void Encode(Node node, IStream stream);
        bool Decode(Node node, IStream stream);

        /**
         * <summary>
         *  This is the invariable (maximal) encoded size for a node
         * </summary>
         */
        ISize EncodedSize { get; }
    }

    public interface IChunkDescriptorEncoder : IEncodable
    {
        /**
         * <summary>
         *  chunk size
         * </summary>
         */
        ISize ChunkSize { get; set; }
    }
}
